﻿using SimpleCrawler;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SimplrCrawler
{
    public partial class Form1 : Form
    {
        static Crawler myCrawler = new Crawler();
        public Form1()
        {
            InitializeComponent();
            myCrawler.miao += changeDetail;
        }

        private void start_Click(object sender, EventArgs e)
        {
                string startUrl = this.startUrl.Text;
                if (startUrl == "") { return; }
                myCrawler.startCrawler(startUrl);
        }

        private void changeDetail(string s)
        {
            lock (richTextBox1)
            {
                Action action = () => richTextBox1.AppendText(s);
                if (this.InvokeRequired)
                {
                    this.Invoke(action);
                }
                else
                {
                    action();
                }
            }
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            startUrl.Text =@"http://www.cnblogs.com/dstang2000/";
        }
    }
}
